@extends('frontend/layouts/bootstrap')

@section('content')
<h2>Контейнерт хийх машины жагсаалт</h2>

{{-- FILTER --}}
<div class="well well-small">
    <form class="form-inline" style="margin: 0;" action="{{ route('car_balance.container.carlist') }}" method="post">
        {{-- CUSTOMER ID --}}
        Customer: {{ Form::select('customer_id', $customer_list, $customer_id, array('class' => 'input-medium')) }}
        {{-- CERTIFICATE READY --}}
        <input type="checkbox" id="cert" name="cert" {{ $cert ? '' : 'checked' }}/> <label for="cert">Include Certificate not ready? </label>
        {{-- NUMBER PLATE READY --}}
        <input type="checkbox" id="numberArrival" name="numberArrival" {{ $numberArrival ? '' : 'checked' }}/> <label for="numberArrival">Include ナンバー到着 not ready? </label>
        {{-- SHAKENSYO READY --}}
        <input type="checkbox" id="shakensyo" name="shakensyo" {{ $shakensyo ? '' : 'checked' }}/> <label for="shakensyo">Include 車検証到着 not ready? </label>

        {{ Form::token() }}
        {{-- BUTTONS --}}
        <button type="submit" class="btn">Apply Filter</button>
        <a href="#" >Reset</a>
    </form>
</div>

@if (count($cars))
<div>{{ count($cars) }} results.</div>
        <table class="table table-bordered table-condensed table-hover">
            <thead style="background-color: #f0f0f0; white-space:nowrap;">
            <tr>
                <td title="Customer">Customer</td>
                <th title="Date">日付</th>
                <th title="Auction">オーク会場</th>
                <th title="Auction no">出品番号</th>
                <th title="Car name">車種</th>
                <th title="Car year">年式 / 年月</th>
                <th title="Chassis number">車体番号</th>
                <th title="Certificate">Certificate</th>
                <th title="Number plate">ナンバー到着</th>
                <th title="Shakensyo">車検証到着</th>
                <th title="Container System Id">Auc.Sheet PDF</th>
                <th title="Container System Id">Cont.Sys.Id</th>
                <th title="Actions">Action</th>
            </tr>
            </thead>
            <tbody style="font-size: 11px;">
            @foreach($cars as $car)
            <tr id="cid_{{ $car->id }}" >
                <td>{{ $car->customer_id }}</td>
                <td>{{ $car->purchase_date }}</td>
                <th>{{ $car->auction_name }}</th>
                <th>{{ $car->lot_no }}</th>
                <th>{{ $car->car_maker }} {{ $car->car_name }}</th>
                <td>{{ $car->car_year }}</br>{{ $car->car_year_month }}</td>
                <td>{{ $car->chasis_no }}</td>
                <td>{{ $car->mail_export_erasure_to_nmc_upload_flag ? '<span class="badge badge-success"><i class="icon icon-ok"></i></span>' : '<span class="badge badge-important"><i class="icon icon-remove"></i></span>' }}</td>
                <td>
                    @if ($car->number_plate_flag != 1 )
                        <span class="badge badge-success"><i class="icon icon-ok"></i></span>
                    @else
                        {{ $car->number_arrival_flag ? '<span class="badge badge-success"><i class="icon icon-ok"></i></span>' : '<span class="badge badge-important"><i class="icon icon-remove"></i></span>' }}
                    @endif
                </td>
                <td>{{ $car->shakensyo_flag ? '<span class="badge badge-success"><i class="icon icon-ok"></i></span>' : '<span class="badge badge-important"><i class="icon icon-remove"></i></span>' }}</td>
                <td>
                    @if ( $car->auction_sheet_upload_flag )
                        <a target="_blank" style="margin-left: 15px;" class="btn btn-success btn-mini" href="{{route('car_balance.main.display', array('type'=>'auction', 'file'=>'auction_sheet_'.$car->chasis_no.'.pdf'))}}" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><i class="icon-zoom-in icon-white"></i></a>
                    @else
                        No pdf.
                    @endif
                </td>
                <td class="csi" bgcolor="{{ Container::getColor($car->container_id) }}">{{ $car->container_id }}</td>
                <td>
                    <a class="btn btn-mini btn-primary btn-change-container" href="#" data-csi="{{ $car->container_id }}" data-cid="{{ $car->id }}">Change container</a>
                </td>
            </tr>
            @endforeach
            </tbody>
        </table>

@else
    Хайлтад тохирох үр дүн алга
@endif

<div class="modal hide fade" id="changeContainerModal">
    <form action="{{ route('car_balance.container.changeCarContainer') }}">
        <div class="modal-header">
            <h2>Change container</h2>
        </div>
        <div class="modal-body">
        </div>
        <div class="modal-footer">
            <a class="btn btn-success btn-ok" href="#">Ok</a>
            <a class="btn btn-cancel" href="#">Cancel</a>
            <a class="btn btn-create btn-primary" href="#">Шинэ Container-т хийх</a>
        </div>
    </form>
</div>

@stop


@section('pagestyles')
<link rel="stylesheet" type="text/css" href={{ asset('assets/chosen-bootstrap/chosen.min.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-daterangepicker/daterangepicker.css') }} />

@stop

@section('pagescripts')
<!--page specific plugin scripts-->
<script type="text/javascript" src={{ asset('assets/chosen-bootstrap/chosen.jquery.min.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/date.js') }} ></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/daterangepicker.js') }}></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('.btn-change-container').on('click', function(e){
            e.preventDefault();
            $('#changeContainerModal').modal('show');
            $('#changeContainerModal .modal-body').html('Loading...');
            $.get($('#changeContainerModal form').attr('action')+'?csi='+$(this).data('csi')+'&cid='+$(this).data('cid'), function(d){
                $('#changeContainerModal .modal-body').html(d);
            });
        });
        $('.btn-ok').on('click', function(e){
            e.preventDefault();
            $.post($('#changeContainerModal form').attr('action'), $('#changeContainerModal form').serialize(), function(d){
                if(d.status = 'success') {
                    $('#changeContainerModal').modal('hide');
                    $('tr#cid_'+ d.cid+' td.csi').text(d.csi).attr('bgcolor', d.color);
                    $('tr#cid_'+ d.cid+' a.btn-change-container').data('csi', d.csi);
                }
                console.log(d);
            })
        });
        $('.btn-create').on('click', function(e){
            e.preventDefault();
            $.post('{{ route('car_balance.container.create') }}', $('#changeContainerModal form').serialize(), function(d){
                if(d.status = 'success') {
                    $('#changeContainerModal').modal('hide');
                    $('tr#cid_'+ d.cid+' td.csi').text(d.csi).attr('bgcolor', d.color);
                    $('tr#cid_'+ d.cid+' a.btn-change-container').data('csi', d.csi);
                } else {
                    alert(d.message);
                }
                console.log(d);
            })
        });
        $('.btn-cancel').on('click', function(e){
            e.preventDefault();
            $('#changeContainerModal').modal('hide');
        });
    });
</script>
@stop